package com.ruoyi.web.controller.workload;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.workload.domain.Workload;
import com.ruoyi.workload.service.IWorkloadService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工作量统计Controller
 *
 * @author ruoyi
 * @date 2025-05-28
 */
@RestController
@RequestMapping("/workload/workload")
public class WorkloadController extends BaseController
{
    @Autowired
    private IWorkloadService workloadService;

    /**
     * 查询工作量统计列表
     */
    @PreAuthorize("@ss.hasPermi('workload:workload:list')")
    @GetMapping("/list")
    public TableDataInfo list(Workload workload)
    {
        startPage();
        List<Workload> list = workloadService.selectWorkloadList(workload);
        return getDataTable(list);
    }

    /**
     * 导出工作量统计列表
     */
    @PreAuthorize("@ss.hasPermi('workload:workload:export')")
    @Log(title = "工作量统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Workload workload)
    {
        List<Workload> list = workloadService.selectWorkloadList(workload);
        ExcelUtil<Workload> util = new ExcelUtil<Workload>(Workload.class);
        return util.exportExcel(list, "工作量统计数据");
    }

    /**
     * 获取工作量统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('workload:workload:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(workloadService.selectWorkloadById(id));
    }

    /**
     * 新增工作量统计
     */
    @PreAuthorize("@ss.hasPermi('workload:workload:add')")
    @Log(title = "工作量统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Workload workload)
    {
        return toAjax(workloadService.insertWorkload(workload));
    }

    /**
     * 修改工作量统计
     */
    @PreAuthorize("@ss.hasPermi('workload:workload:edit')")
    @Log(title = "工作量统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Workload workload)
    {
        workload.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(workloadService.updateWorkload(workload));
    }

    /**
     * 删除工作量统计
     */
    @PreAuthorize("@ss.hasPermi('workload:workload:remove')")
    @Log(title = "工作量统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workloadService.logicDeleteWorkload(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
